use serde::Serialize;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error(transparent)]
    Io(#[from] std::io::Error),

    #[error("Unsupported platform for CLI installation")]
    UnsupportedPlatform,

    #[error("Could not determine home directory")]
    NoHomeDirectory,

    #[error("Refusing to remove non-symlink CLI path: {0}")]
    NonSymlinkCliPath(String),
}

impl Serialize for Error {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.to_string().as_ref())
    }
}

pub type Result<T> = std::result::Result<T, Error>;
